package org.codeart.api_driver.service;

import com.alibaba.fastjson.JSONObject;
import org.codeart.api_driver.remote.ServiceOrderClient;
import org.codeart.api_driver.remote.ServiceSseClient;
import org.codeart.common.constant.IdentityEnum;
import org.codeart.common.request.OrderRequest;
import org.codeart.common.request.PushRequest;
import org.codeart.common.util.HttpStatus;
import org.codeart.common.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PayService {
    
    @Autowired
    private ServiceSseClient serviceSseClient;

    @Autowired
    private ServiceOrderClient serviceOrderClient;
    
    public boolean pushPayInfo(Long orderId, Double price, Long passengerId) {
        JSONObject message = new JSONObject();
        message.put("price", price);
        message.put("orderId", orderId);
        // 修改订单状态
        OrderRequest orderRequest = new OrderRequest();
        orderRequest.setOrderId(orderId);
        serviceOrderClient.pushPayInfo(orderRequest);

        PushRequest pushRequest = new PushRequest();
        pushRequest.setContent(message.toString());
        pushRequest.setUserId(passengerId);
        pushRequest.setIdentity(IdentityEnum.PASSENGER.value());
        
        // 推送消息
        R<String> r = serviceSseClient.push(passengerId, IdentityEnum.PASSENGER.value(), message.toJSONString());
        return r.getCode() == HttpStatus.HTTP_OK;
    }
    
    

}
